<?php
	class Cola {
		protected $cola		= Array();
		protected $fondo	= '';
		protected $numel	= 0;
		
		public function __construct($cantidad = False) {
			if (!$cantidad)
				die('Asigne una cantidad para la cola');
			for ($i = 0; $i < $cantidad; $i++)
				$this->cola[] = '';
			$this->fondo = '';
			$this->numel = 0;
			$this->showCola();
		}
		
		public function isEmpty() {
			return ($this->getNumel() == 0 ? True : False);
		}
		
		public function isFull() {
			return ($this->getNumel() == $this->getNumelMax() ? True : False);
		}
		
		public function add($element = False) {
			if (!$element) {
				echo '<DIV>Asigne un valor para agregar</DIV>';
				return False;
			}
			if ($this->isFull()) {
				echo "<DIV>La cola esta llena. No se pudo agregar el elemento '$element'.</DIV>";
				return False;
			}
			$this->cola[$this->getNumel()] = $element;
			$this->setFondo($element);
			$this->incNumel();
			$this->showCola();
			return True;
		}
		
		public function del() {
			if ($this->isEmpty()) {
				echo '<DIV>La cola esta vacia. No hay elementos para eliminar.</DIV>';
				return False;
			}
			for ($i = 1; $i <= $this->getNumel(); $i++)
				$this->cola[($i - 1)] = $this->cola[$i];
			for ($i = $this->getNumel(); $i < $this->getNumelMax(); $i++)
				$this->cola[$i] = '';
			$this->decNumel();
			$this->showCola();
			return True;
		}
		
		public function getNumel() {
			return $this->numel;
		}
		
		public function getNumelMax() {
			return count($this->cola);
		}
		
		public function getFondo() {
			return $this->fondo;
		}
		
		public function getFrente() {
			return $this->cola[0];
		}
		
		public function showCola() {
			echo '<DIV><TABLE border=\'1\'><TR>';
			foreach ($this->cola AS $item) {
				echo '<TD width=\'80px\' align=\'center\'>' . ($item == '' ? '<I>empty</I>' : $item) . '</TD>';
			}
			echo '</TR></TABLE></DIV>';
		}
		
		public function showValues() {
			echo '<DIV><TABLE border=\'0\'>';
			echo '<TR><TD>Numel:</TD><TD>'. $this->getNumel() .'</TD></TR>';
			echo '<TR><TD>Frente:</TD><TD>'. $this->getFrente() .'</TD></TR>';
			echo '<TR><TD>Fondo:</TD><TD>'. $this->getFondo() .'</TD></TR>';
			echo '</TABLE></DIV>';
		}
		
		protected function setFondo($element) {
			$this->fondo = $element;
		}
		
		protected function incNumel() {
			$this->numel++;
		}
		
		protected function decNumel() {
			$this->numel--;
		}
	}
?>